﻿Imports System.Data
Imports System.Data.SqlClient
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL

Public Class DesgloseDALC
    'Public Function ListaDesglose(ByVal objDesglose As DesgloseBE) As DataTable

    '    Dim sqlListar As String
    '    Dim objListaDesglose As New List(Of DesgloseBE)
    '    Dim objListaDesgloseBE As DesgloseBE = Nothing
    '    Dim arrSqlParameter(1) As SqlParameter
    '    Dim ds As DataSet
    '    Dim dt As DataTable

    '    Dim objDatos As New AccesoDatos()
    '    Dim blnExito As Boolean
    '    Dim strMensaje As String = String.Empty
    '    Dim intI As Integer = 0

    '    Try 
    '        sqlListar = "Desglose_Listar"

    '        arrSqlParameter(0) = New SqlParameter("@KVJE", System.Data.SqlDbType.VarChar)
    '        arrSqlParameter(0).Value = objDesglose.Kvje 

    '        arrSqlParameter(1) = New SqlParameter("@KBLI", System.Data.SqlDbType.VarChar)
    '        arrSqlParameter(1).Value = objDesglose.KBle 



    '        ds = objDatos.DevuelveDataSet(sqlListar, blnExito, strMensaje, arrSqlParameter)
    '        dt = ds.Tables(0)

    '    Catch ex As Exception
    '        MsgBox(ex.Message, vbCritical, "Error del sistema")
    '        Return Nothing
    '        Exit Function
    '    End Try

    '    Return dt
    'End Function

    Public Function ListaDesglose_BLImpo(ByVal objDesglose As DesgloseBE) As DataTable

        Dim sqlListar As String
        Dim objListaDesglose As New List(Of DesgloseBE)
        Dim objListaDesgloseBE As DesgloseBE = Nothing
        Dim arrSqlParameter(4) As SqlParameter
        Dim ds As DataSet
        Dim dt As DataTable

        Dim objDatos As New AccesoDatos()
        Dim blnExito As Boolean
        Dim strMensaje As String = String.Empty
        Dim intI As Integer = 0

        Try
            sqlListar = "up_ListarBL_Desglose"

            arrSqlParameter(0) = New SqlParameter("@KVJE", System.Data.SqlDbType.Int)
            arrSqlParameter(0).Value = objDesglose.Kvje

            arrSqlParameter(1) = New SqlParameter("@PtoOrigen", System.Data.SqlDbType.VarChar)
            arrSqlParameter(1).Value = objDesglose.Ptoo

            arrSqlParameter(2) = New SqlParameter("@Bl", System.Data.SqlDbType.VarChar)
            arrSqlParameter(2).Value = objDesglose.Nume

            arrSqlParameter(3) = New SqlParameter("@BlDesglose", System.Data.SqlDbType.VarChar)
            arrSqlParameter(3).Value = objDesglose.KBld

            arrSqlParameter(4) = New SqlParameter("@Bl_Flag", System.Data.SqlDbType.Char)
            arrSqlParameter(4).Value = objDesglose.Flag


            ds = objDatos.DevuelveDataSet(sqlListar, blnExito, strMensaje, arrSqlParameter)
            dt = ds.Tables(0)

        Catch ex As Exception
            MsgBox(ex.Message, vbCritical, "Error del sistema")
            Return Nothing
            Exit Function
        End Try

        Return dt
    End Function

    Public Function ListaDesgloseDetalle(ByVal objDesglose As DesgloseBE, ByRef dt As DataTable, ByRef sMensaje As String, ByRef bExito As Boolean) As DataTable

        Dim sqlListar As String
        Dim objListaDesglose As New List(Of DesgloseBE)
        Dim objListaDesgloseBE As DesgloseBE = Nothing
        Dim arrSqlParameter(1) As SqlParameter
        Dim ds As DataSet
        'Dim dt As DataTable

        Dim objDatos As New AccesoDatos()
        'Dim blnExito As Boolean
        'Dim strMensaje As String = String.Empty
        Dim intI As Integer = 0

        Try
            sqlListar = "up_Desglose_ObtenerDet"

            arrSqlParameter(0) = New SqlParameter("@Kvje", System.Data.SqlDbType.Int)
            arrSqlParameter(0).Value = objDesglose.Kvje

            arrSqlParameter(1) = New SqlParameter("@KBle", System.Data.SqlDbType.Int)
            arrSqlParameter(1).Value = objDesglose.KBle


            ds = objDatos.DevuelveDataSet(sqlListar, bExito, sMensaje, arrSqlParameter)
            dt = ds.Tables(0)

        Catch ex As Exception
            MsgBox(ex.Message, vbCritical, "Error del sistema")
            Return Nothing
            Exit Function
        End Try

        Return dt
    End Function

    Public Function InsertarDesglose(ByVal objDesglose As DesgloseBE, ByRef bExito As Boolean, ByRef sMensaje As String) As Boolean

        Dim arrSqlParameter(11) As SqlParameter

        Try

            arrSqlParameter(0) = New SqlParameter()
            arrSqlParameter(0).ParameterName = "@Kvje"
            arrSqlParameter(0).SqlDbType = SqlDbType.Int
            arrSqlParameter(0).Direction = ParameterDirection.Input
            arrSqlParameter(0).Value = objDesglose.Kvje

            arrSqlParameter(1) = New SqlParameter()
            arrSqlParameter(1).ParameterName = "@KBle"
            arrSqlParameter(1).SqlDbType = SqlDbType.Int
            arrSqlParameter(1).Direction = ParameterDirection.Input
            arrSqlParameter(1).Value = objDesglose.KBle

            arrSqlParameter(2) = New SqlParameter()
            arrSqlParameter(2).ParameterName = "@KBLd"
            arrSqlParameter(2).SqlDbType = SqlDbType.Int
            arrSqlParameter(2).Direction = ParameterDirection.Input
            arrSqlParameter(2).Value = objDesglose.KBld

            arrSqlParameter(3) = New SqlParameter()
            arrSqlParameter(3).ParameterName = "@Nume"
            arrSqlParameter(3).SqlDbType = SqlDbType.VarChar
            arrSqlParameter(3).Direction = ParameterDirection.Input
            arrSqlParameter(3).Value = objDesglose.Nume

            arrSqlParameter(4) = New SqlParameter()
            arrSqlParameter(4).ParameterName = "@Csg"
            arrSqlParameter(4).SqlDbType = SqlDbType.VarChar
            arrSqlParameter(4).Direction = ParameterDirection.Input
            arrSqlParameter(4).Value = objDesglose.Consig

            arrSqlParameter(5) = New SqlParameter()
            arrSqlParameter(5).ParameterName = "@Cont"
            arrSqlParameter(5).SqlDbType = SqlDbType.VarChar
            arrSqlParameter(5).Direction = ParameterDirection.Input
            arrSqlParameter(5).Value = objDesglose.Conten

            arrSqlParameter(6) = New SqlParameter()
            arrSqlParameter(6).ParameterName = "@Peso"
            arrSqlParameter(6).SqlDbType = SqlDbType.Decimal
            arrSqlParameter(6).Direction = ParameterDirection.Input
            arrSqlParameter(6).Value = objDesglose.Peso

            arrSqlParameter(7) = New SqlParameter()
            arrSqlParameter(7).ParameterName = "@Obs"
            arrSqlParameter(7).SqlDbType = SqlDbType.VarChar
            arrSqlParameter(7).Direction = ParameterDirection.Input
            arrSqlParameter(7).Value = objDesglose.Obse

            arrSqlParameter(8) = New SqlParameter()
            arrSqlParameter(8).ParameterName = "@Usu"
            arrSqlParameter(8).SqlDbType = SqlDbType.VarChar
            arrSqlParameter(8).Direction = ParameterDirection.Input
            arrSqlParameter(8).Value = objDesglose.Usu

            arrSqlParameter(9) = New SqlParameter()
            arrSqlParameter(9).ParameterName = "@TOPE"
            arrSqlParameter(9).SqlDbType = SqlDbType.Char
            arrSqlParameter(9).Direction = ParameterDirection.Input
            arrSqlParameter(9).Value = objDesglose.TOPE

            arrSqlParameter(10) = New SqlParameter()
            arrSqlParameter(10).ParameterName = "@Estado"
            arrSqlParameter(10).SqlDbType = SqlDbType.VarChar
            arrSqlParameter(10).Direction = ParameterDirection.Input
            arrSqlParameter(10).Value = objDesglose.Estado

            arrSqlParameter(11) = New SqlParameter()
            arrSqlParameter(11).ParameterName = "@BLHijo"
            arrSqlParameter(11).SqlDbType = SqlDbType.VarChar
            arrSqlParameter(11).Direction = ParameterDirection.Input
            arrSqlParameter(11).Value = objDesglose.BLHijo



            Dim oDatos As New AccesoDatos()
            oDatos.EjecutaSP("up_Desglose_Edicion", bExito, sMensaje, arrSqlParameter)
            Return bExito

        Catch ex As Exception
            Throw
        End Try

    End Function


End Class
